package com.demo.jfinal.redis.running;

import org.apache.log4j.Logger;

import com.demo.jfinal.model.ApiOrders;
import com.demo.jfinal.redis.Redis;
import com.google.gson.Gson;

/**
 * 接收订购中的订单
 * 处理类
 */
public class ApiOrdersWorker implements Runnable, OrderUtils {

	private static Logger logger = Logger.getLogger(ApiOrdersWorker.class);

	public void run() {
		while (true) {
			String orderId = "";
			try {
				ApiOrders order = Redis.use("redisOrderPlugin").blpop("apiOrders");
				if (order != null) {
					order.save();
					logger.info("apiorders:" + new Gson().toJson(order) + " inner DB successful");
				}
			} catch (Exception e) {
				e.printStackTrace();
				logger.error("线程处理队列中订单ID" + orderId + "异常" + e);
			}
		}
	}
}
